
using System;

namespace JEngine.Framework
{
    public static class RankHelper
    {
        private const int System_UTC8 = 8; // 北京时间
        private const int System_RefreshHour = 6; // 系统刷新时间

        

        private static int shift(DayOfWeek dayOfWeek)
        {
            return dayOfWeek switch
            {
                DayOfWeek.Monday => -0,
                DayOfWeek.Tuesday => -1,
                DayOfWeek.Wednesday => -2,
                DayOfWeek.Thursday => -3,
                DayOfWeek.Friday => -4,
                DayOfWeek.Saturday => -5,
                DayOfWeek.Sunday => -6,
                _ => 0
            };
        }

       
        public static void log_time(long time)
        {
            var utc = new DateTime(time); //当期时间
            var utc8 = utc.AddHours(System_UTC8); // 算成北京时间
            var day8 = utc8 //目标时间
                    .AddHours(System_RefreshHour - utc8.Hour)
                    .AddMinutes(-utc8.Minute)
                    .AddSeconds(-utc8.Second)
                    .AddMilliseconds(-utc8.Millisecond);
            var day = day8.AddHours(-System_UTC8); // 返回utc时间
            var week8 = utc8 //目标时间
                    .AddDays(shift(utc8.DayOfWeek))
                    .AddHours(System_RefreshHour - utc8.Hour)
                    .AddMinutes(-utc8.Minute)
                    .AddSeconds(-utc8.Second)
                    .AddMilliseconds(-utc8.Millisecond);
            var week = week8.AddHours(-System_UTC8); // 返回utc时间
            var month8 = utc8 //目标时间
                    .AddDays(1 - utc8.Day)
                    .AddHours(System_RefreshHour - utc8.Hour)
                    .AddMinutes(-utc8.Minute)
                    .AddSeconds(-utc8.Second)
                    .AddMilliseconds(-utc8.Millisecond);
            var month = month8.AddHours(-System_UTC8); // 返回utc时间

            JLog.LogWarning("===[time:{time}]===", time);
            JLog.LogWarning("[crt  ] utc8:{utc8}, utc:{utc}", utc8, utc);
            JLog.LogWarning("[day  ] utc8:{utc8}, utc:{utc}", day8, day);
            JLog.LogWarning("[week ] utc8:{utc8}, utc:{utc}", week8, week);
            JLog.LogWarning("[month] utc8:{utc8}, utc:{utc}", month8, month);
            JLog.LogWarning("---[time:{time}]---", time);
        }

      
    }
        
}
